﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.Entities.ESGRatings;
using Sustainalytics.ESGComputing.Service.Helpers;
using Sustainalytics.ESGRatings.RedisCache;

namespace Sustainalytics.ESGComputing.Service.Tests
{
    [TestClass]
    public class ESGDataSourceMonitorTests
    {

        [TestInitialize]
        public void Initialize()
        {
           
           
            var redis = ESGRatingsRedisCache.DefaultESGRatingsAppCache();

            redis.Remove("WeightMatrix");
            redis.Remove("CompanyScores");
            redis.Remove("ReferenceUniverse");
        }



        [TestCleanup]
        public void Cleanup()
        {
           
        }
        


        [TestMethod()]
        public void ESGDataSourceMonitor_basicLoadingdataTest()
        {

            try
            {
                var receivedMsg = string.Empty;
                EventHandler<string> onmessage = (object sender, string message) => { receivedMsg = message; };
                var redis = ESGRatingsRedisCache.DefaultESGRatingsAppCache(onmessage);

                var companies = new List<RawScore>
                {
                    new RawScore()
                    {
                        Id = Guid.NewGuid(),
                        CompanyType = "public",
                        IndustryGroup = "I1",
                        PeerGroup = "P1",
                        TemplateType = "Type A"
                    },
                    new RawScore()
                    {
                        Id = Guid.NewGuid(),
                        CompanyType = "public",
                        IndustryGroup = "I1",
                        PeerGroup = "P1",
                        TemplateType = "Type A"
                    },
                    new RawScore()
                    {
                        Id = Guid.NewGuid(),
                        CompanyType = "public",
                        IndustryGroup = "I1",
                        PeerGroup = "P1",
                        TemplateType = "Type A"
                    },
                    new RawScore()
                    {
                        Id = Guid.NewGuid(),
                        CompanyType = "public",
                        IndustryGroup = "I1",
                        PeerGroup = "P1",
                        TemplateType = "Type A"
                    }
                };
                redis.Set(companies);


                var weights = new List<WeightMatrix>
                {
                    new WeightMatrix() {Id = Guid.NewGuid(), Name = "m1"},
                    new WeightMatrix() {Id = Guid.NewGuid(), Name = "m2"},
                    new WeightMatrix() {Id = Guid.NewGuid(), Name = "m3"},
                    new WeightMatrix() {Id = Guid.NewGuid(), Name = "m4"}
                };
                redis.Set(weights);


                var refUniv = new List<ReferenceUniverse>
                {
                    new ReferenceUniverse() {Id = Guid.NewGuid(), Name = "u1"},
                    new ReferenceUniverse() {Id = Guid.NewGuid(), Name = "u2"},
                    new ReferenceUniverse() {Id = Guid.NewGuid(), Name = "u3"},
                    new ReferenceUniverse() {Id = Guid.NewGuid(), Name = "u4"}
                };
                redis.Set(refUniv);

                var dm = ESGDataSource.GetInstance();
                dm.LoadDataFromCache();
                Assert.Inconclusive();
               
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        [TestMethod()]
        public void FullcCircuitTest()
        {
            // using local redis 
            // upload a weight matrix at controller level
            // upload a ref universe at contoller level
            // sync weights, scores, ref universe
            // load ESGDataSourceMonitor
            // test otuput at controller level
            
            throw new NotImplementedException();
        }
    }
}
